package com.ruoyi.web.controller.server;

import java.util.List;
import javax.validation.Valid;

import com.ruoyi.server.domain.dto.ServerRegionAddDTO;
import com.ruoyi.server.domain.dto.ServerRegionPageDTO;
import com.ruoyi.server.domain.dto.ServerRegionUpdateDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.server.domain.ServerRegion;
import com.ruoyi.server.service.IServerRegionService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 区服Controller
 *
 * @author ghostmen
 * @date 2024-10-31
 */
@Validated
@RestController
@RequestMapping("/server/region")
@Api(value = "区服", tags = "区服接口")
public class ServerRegionController extends BaseController {

    @Autowired
    private IServerRegionService serverRegionService;

    /**
     * 查询区服列表
     */
    @PreAuthorize("@ss.hasPermi('server:region:list')")
    @GetMapping("/list")
    @ApiOperation(value = "查询区服列表", notes = "传入serverRegion")
    public TableDataInfo list(ServerRegionPageDTO page) {
        List<ServerRegion> list = serverRegionService.selectServerRegionList(page);
        return getDataTable(list);
    }



    /**
     * 获取区服详细信息
     */
    @PreAuthorize("@ss.hasPermi('server:region:query')")
    @GetMapping(value = "/{regionId}")
    @ApiOperation(value = "获取区服详细信息", notes = "传入regionId")
    public AjaxResult getInfo(@PathVariable("regionId") Long regionId) {
        return success(serverRegionService.selectServerRegionByRegionId(regionId));
    }

    /**
     * 新增区服
     */
    @PreAuthorize("@ss.hasPermi('server:region:add')")
    @Log(title = "区服", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value = "新增区服", notes = "传入addDTO")
    public AjaxResult add(@Valid @RequestBody ServerRegionAddDTO addDTO) {
        addDTO.setLoginUser(getLoginUser());
        return toAjax(serverRegionService.insertServerRegion(addDTO));
    }

    /**
     * 修改区服
     */
    @PreAuthorize("@ss.hasPermi('server:region:edit')")
    @Log(title = "区服", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(value = "修改区服", notes = "传入updateDTO")
    public AjaxResult edit(@Valid @RequestBody ServerRegionUpdateDTO updateDTO) {
        updateDTO.setLoginUser(getLoginUser());
        return toAjax(serverRegionService.updateServerRegion(updateDTO));
    }

    /**
     * 删除区服
     */
    @PreAuthorize("@ss.hasPermi('server:region:remove')")
    @Log(title = "区服", businessType = BusinessType.DELETE)
    @DeleteMapping("/{regionIds}")
    @ApiOperation(value = "删除区服", notes = "传入regionIds")
    public AjaxResult remove(@PathVariable Long[] regionIds) {
        return toAjax(serverRegionService.deleteServerRegionByRegionIds(regionIds));
    }
}
